/**
 * Created by hushuyan on 2022/2/29.
 */
var vue = new Vue({
    el: "#app",
    data: {
        username: "",
        password: "",
        rpassword: "",
        email: "",
        code:"",
        mobile:"",
        phone : "",
        url: ""
    },
    methods: {
        sendCode: function(){
           var mobile = document.getElementById("phone_input").value
            if (mobile!=''){
                util.successTips("短信验证码发送成功")
            }else {util.errorTips("请输入手机号")
            }
            this.$http.post('/user/sendCode.do',
                {
                    phone: mobile
                },
             {emulateJSON:true})

        },

        handleClick: function () {
            
            this.$http.post('/user/signup.do', {
                username: this.username,
                password: this.password,
                code: this.code,
                email: this.email,
                phone: this.phone
            }, {emulateJSON:true}).then(this.successCallback,this.errorCallback)
        },
        successCallback: function ( res ) {
                console.log(res);
            res = res.body;
            console.log(res.msg);
            console.log(res.msg=="注册成功");

            if (res.msg=="注册成功"){
                window.location.href = '/login';
            }
            if( res.data && res.status == 0){
                console.log("this.url > 0:" + (this.url.length > 0));
                if ( this.url.length > 0 ){
                    window.location.href = this.url ;
                }else {
                    window.location.href = '/index';
                }
            }else {
                util.errorTips( res.msg )
            }
        },
        errorCallback: function ( res ) {
            util.errorTips()
        }
    },
    mounted: function () {
        this.url = this.$refs.urlRef.value.trim();
        console.log( "this.url:" + this.url );
    }
});